<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>canvas</title>
    <style>
        #canvas {
            background-color: pink;
        }
    </style>
</head>

<body>
    <!--  -->
    <canvas id="canvas" height="400px" width="800px"></canvas>
    <script>
        const canvas = document.getElementById('canvas')
        // 获取2b画笔
        const context = canvas.getContext("2d")

        context.beginPath()

        context.strokeStyle = "#000" //线的颜色
        // 画线
        context.moveTo(100, 100) //开始点
        context.lineTo(200, 200)
        context.lineTo(200, 300)
        context.stroke() //结束点

        context.closePath()

        // 矩形 strokeRect(x, y, width, height)
        context.strokeRect(300, 100, 200, 50)

        context.fillStyle = "yellowgreen";  //默认黑色
        context.fillRect(300, 300, 300, 300)
        context.fillRect(300, 100, 200, 50)

        // 圆(x,y,r,起始角度,结束角度,顺/逆true)
        context.arc(500, 200, 50, 0, 2 * Math.PI, true)
        context.stroke() //不太懂
        context.fill() //填满
        context.closePath() //关闭路径

        // 文字
        context.font = '20px 宋体'
        context.fillText('lalalal', 600, 300)

        // 清空画布
        // context.clearRect(0, 0, 800, 400)
    </script>
</body>

</html>